<template>
	<view class="default-background">
		<view class="index-page">
				<scroll-view>
					<view class="house-item" v-for="house in this.houseList" @click="getDetail(house.id)">
						<view class="img-group">
							<image :src="house.firstImg" class="first-img" mode="aspectFill"></image>
						</view>
						<view class="text-group">
							<view class="title limit-one-line">{{house.title}}</view>
							<view class="introduce limit-one-line">{{house.introduce}}</view>
							<uni-dateformat :date="house.createTime" format="yyyy-MM-dd hh:mm:ss" class="create-time"></uni-dateformat>
						</view>
					</view>
					<view class="page-bottom"></view>
				</scroll-view>
		</view>
	</view>
</template>

<script>
	import config  from "@/config/app.js"
	export default {
		data() {
			return {
				page: 1,
				limit: 6,
				houseList: []
			};
		},
		methods: {
			async getHouseList() {
				this.$request.request({
					url: "/house/viewHistoryList",
					method: "GET",
					data: {
						page: this.page,
						limit: this.limit
					}
				}).then(res=>{
					if (res.code == 200) {
						for (let i=0; i<res.data.length; i++) {
							res.data[i].firstImg = config.IMG_URL + JSON.parse(res.data[i].pic)[0]
						}
						if (res.data.length <= 0) {
							uni.showToast({
								title: "没有更多数据了~",
								icon: "none"
							})
							return;
						} else {
							this.houseList = this.houseList.concat(res.data)
						}
					} else {
						uni.navigateTo({
							url: "../user/login"
						})
					}
				})
			},
			getDetail(id) {
				uni.navigateTo({
					url: "../house/detail?id=" + id
				})
			},
			onShow() {
			},
			onLoad() {
				this.page = 1;
				this.houseList = [];
				this.getHouseList();
			},
			onPullDownRefresh() {
				this.page = 1;
				this.houseList = [];
				this.searchText = "";
				this.getHouseList();
				uni.stopPullDownRefresh();
			},
			async onReachBottom() {
				this.page += 1;
				this.getHouseList();
			}
		}
	}
</script>

<style lang="scss" scoped>
.index-page {
		
		.house-item {
			background-color: #FFFFFF;
			padding: 20rpx;
			display: flex;
			border-bottom: 3rpx solid #F2F1F6;
			
			.img-group {
				
				.first-img {
					width: 300rpx;
					height: 180rpx;
					border-radius: 20rpx;
				}
			}
			
			.text-group {
				padding: 0 20rpx;
				flex: 1;
				width: 360rpx;
				
				.title {
					font-size: 20px;
				}
				
				.introduce {
					height: 40rpx;
					margin-top: 30rpx;
					font-size: 16px;
					color: #999999;
				}
				
				.create-time {
					font-size: 16px;
					color: #999999;
				}
				
			}
		}
	}
</style>
